<?php
use Guzzle\Http\Url;
class TbfUrl {
    //给url添加一些参数,一定不会覆盖掉原来的
    static function addParamToUrl($url,$data){
        foreach($data as $key=>$value){
            if (strpos($url,'?')===false){
                $url = $url.'?'.xupve($key).'='.xupve($value);
            }else{
                $url = $url.'&'.xupve($key).'='.xupve($value);
            }
        }
        return $url;
    }

    //给url设置一些参数,会覆盖掉原有的
    static function setParamToUrl($url,$data){
        $obj = Url::factory($url);
        $queryObj = $obj->getQuery();
        foreach($data as $key=>$value){
            $queryObj->set($key,$value);
        }
        return (string)$obj;
    }
    static function getUrlQueryArray($url){
        $query = parse_url($url,PHP_URL_QUERY);
        $data = array();
        parse_str($query,$data);
        return $data;
    }
    static function getPathFromUrl($url){
        return parse_url($url,PHP_URL_PATH);
    }
} 